package com.ruoyi.web.controller.gxs;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gxs.domain.GxsAddstudent;
import com.ruoyi.gxs.service.IGxsAddstudentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 新增学生Controller
 * 
 * @author 高晓松
 * @date 2024-03-01
 */
@RestController
@RequestMapping("/gxs/addstudent")
public class GxsAddstudentController extends BaseController
{
    @Autowired
    private IGxsAddstudentService gxsAddstudentService;

    /**
     * 查询新增学生列表
     */
    //  @PreAuthorize("@ss.hasPermi('gxs:addstudent:list')")
    @GetMapping("/list")
    public TableDataInfo list(GxsAddstudent gxsAddstudent)
    {
        startPage();
        List<GxsAddstudent> list = gxsAddstudentService.selectGxsAddstudentList(gxsAddstudent);
        return getDataTable(list);
    }

    /**
     * 导出新增学生列表
     */
    //   @PreAuthorize("@ss.hasPermi('gxs:addstudent:export')")
    @Log(title = "新增学生", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GxsAddstudent gxsAddstudent)
    {
        List<GxsAddstudent> list = gxsAddstudentService.selectGxsAddstudentList(gxsAddstudent);
        ExcelUtil<GxsAddstudent> util = new ExcelUtil<GxsAddstudent>(GxsAddstudent.class);
        util.exportExcel(response, list, "新增学生数据");
    }

    /**
     * 获取新增学生详细信息
     */
//    @PreAuthorize("@ss.hasPermi('gxs:addstudent:query')")
    @GetMapping(value = "/{gxsId}")
    public AjaxResult getInfo(@PathVariable("gxsId") Long gxsId)
    {
        return success(gxsAddstudentService.selectGxsAddstudentByGxsId(gxsId));
    }

    /**
     * 新增新增学生
     */
//    @PreAuthorize("@ss.hasPermi('gxs:addstudent:add')")
    @Log(title = "新增学生", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GxsAddstudent gxsAddstudent)
    {
        return toAjax(gxsAddstudentService.insertGxsAddstudent(gxsAddstudent));
    }

    /**
     * 修改新增学生
     */
//    @PreAuthorize("@ss.hasPermi('gxs:addstudent:edit')")
    @Log(title = "新增学生", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GxsAddstudent gxsAddstudent)
    {
        return toAjax(gxsAddstudentService.updateGxsAddstudent(gxsAddstudent));
    }

    /**
     * 删除新增学生
     */
//    @PreAuthorize("@ss.hasPermi('gxs:addstudent:remove')")
    @Log(title = "新增学生", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gxsIds}")
    public AjaxResult remove(@PathVariable Long[] gxsIds)
    {
        return toAjax(gxsAddstudentService.deleteGxsAddstudentByGxsIds(gxsIds));
    }


    //导入
    @Log(title = "学生管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<GxsAddstudent> util = new ExcelUtil<GxsAddstudent>(GxsAddstudent.class);
        List<GxsAddstudent> studentList = util.importExcel(file.getInputStream());

        String operName = getUsername();
        String message = gxsAddstudentService.importStudent(studentList, updateSupport, operName);
        return success(message);
    }



    //下载模板
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<GxsAddstudent> util = new ExcelUtil<GxsAddstudent>(GxsAddstudent.class);
        util.importTemplateExcel(response, "学生信息");
    }

}
